<?php

/**
 * 分组表
 * Created by ymk
 * User: Administrator
 * Date: 2018/6/20
 * Time: 16:00
 */

namespace MeetUp\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Group extends Base
{
    use SoftDeletes;
    protected $table = 'group';

    public $primaryKey = 'group_id';

    protected $dates = ['deleted_at'];

    protected $fillable = ['group_id','group_name','start_uid','manage_uid','category_id','group_area','group_thumimg','group_bigimg','group_content','group_via'];

    //分组的详情
    public function group_details($data,$uid,$url){
        $user_group = new UserGroup();
        foreach ($data as $key => $value){
            //是否加入该小组
            $flag = $user_group->where(['groupid'=>$value['group_id'],'uid'=>$uid])->first();
            if($flag){
                $data[$key]['is_join'] = 1;
            }else{
                $data[$key]['is_join'] = 0;
            }
            //该分组有多少成员
            $data[$key]['count'] = $user_group->where(['groupid'=>$value['group_id']])->count();
            //图片地址
            $data[$key]['group_thumimg'] = $url.$value['group_thumimg'];
        }
        return $data;
    }
}